package com.pshcp.service;

import com.pshcp.common.enums.CommonStatusEnum;
import com.pshcp.domain.model.Protocol;
import com.pshcp.domain.model.SmsCaptcha;
import com.pshcp.mapper.ProtocolMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/12/30 18:41
 */
@Service
public class ProtocolService {

    @Autowired
    private ProtocolMapper protocolMapper;

    public Protocol getProtocolByType(String type) {
        Example example = new Example(Protocol.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("type", type);
        criteria.andEqualTo("status", CommonStatusEnum.INIT.getCode());
        example.setOrderByClause(" created_time desc");
        List<Protocol> list = protocolMapper.selectByExample(example);
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }
}
